package gui;

import domain.*;
import domain.player.*;
import javax.swing.JLabel;

/**
 * GUIController handles request between the GUI elements and the logic.
 * It's part of the glue between the backend and the frontend.
 */
public class GUIController {

	private GameFrame gameFrame;
	private GameBoard gameBoard;
	private DomainController logicController;

	public GUIController() {
		this.logicController = new DomainController(this);
		gameFrame = new GameFrame(this);
		gameBoard = new GameBoard(this);
	}

	/** Start game */
	public void startGame() {
		logicController.startGame();
	}

	/** Quit game */
	public void quitGame() {
		logicController.quitGame();
		logicController = null;
		gameBoard = null;
		gameFrame = null;
	}

	/** Return the Player object for playerNum */
	public Player getPlayer(int playerNum) {
		return logicController.getPlayer(playerNum);
	}

	/* Add players by calling the GameManager */
	public void addPlayers(Player player1, Player player2) {
		logicController.addPlayers(player1, player2);
	}

	/** Show the winner dialog */
	public void showWinnerDialog(Player winner) {
		new WinnerDialog(winner);
	}

	/** Show the tie dialog */
	public void showDrawnDialog() {
		new TieDialog();
	}

	/** Adds a disc to the game grid and board */
	public void addDisc(int column) {
		gameBoard.animateDisc(column);
		gameBoard.updateGameBoard();
	}

	/** Returns the game board panel */
	public GameBoard getGameBoardPanel() {
		return gameBoard;
	}

	/** Returns the a JLabel matrix, representing the visual game board */
	public JLabel[][] getGameBoard() {
		return gameBoard.getGameBoard();
	}

	/** Resets the ongoing game */
	public void resetGame() {
		// First reset the stored values (grid)...
		logicController.resetGameGrid();
		// ... then the graphics (board):
		gameBoard.resetGameBoard();
	}

	public void resetGameBoard() {
		gameBoard.resetGameBoard();
	}

	/** Sets the current player's name by calling the GameFrame */
	public void setCurrentPlayerFrameName(Player currentPlayer) {
		gameFrame.updateCurrentPlayer(currentPlayer);
	}

	/** Returns the game grid as an Disc matrix from GameGrid */
	public GameGrid getGameGrid() {
		return logicController.getGameGrid();
	}

	/** Returns the logic controller */
	public DomainController getLogicController() {
		return logicController;
	}

	/** Returns the Player object for the current player from the logicController */
	public Player getCurrentPlayer() {
		return logicController.getCurrentPlayer();
	}

	/** Presents the winner board */
	public void presentWinnerBoard(GameRules gameRules) {
		gameBoard.presentWinnerBoard(gameRules.getWinnerPoints());
	}


        public void presentMoveWithAndWithout(int move, int nrOfMovesMM, int nrOfMovesMMABP){
            new DebugDialog(move, nrOfMovesMM, nrOfMovesMMABP);
        }

        public void setDebug(boolean debug){
            logicController.setDebug(debug);
        }

		//TODO: Remove this.
        public void presentSetBoardDialog(){
            new SetDialog(this.logicController);
        }
        
        
        public void updateGameFrame(){
            gameFrame.updateGameFrame();
        }
}
